﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {

        Model1 model1 = new Model1();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }


        public ActionResult HH()
        {

            var list = model1.Task.ToList();

            return View(list);
        }

        public ActionResult AA(int id)
        {

            //Request.QueryString["id"];
            Task task = model1.Task.FirstOrDefault(p => p.TaskID == id);


            return View(task);
        }


        [HttpPost]
        public ActionResult Delete(int id)
        {          
            Task task = model1.Task.FirstOrDefault(p => p.TaskID == id);
            if (task!=null)
            {
                model1.Task.Remove(task);
                var result =  model1.SaveChanges()>0;
                return Json(result);
            }
            return Json(false);

        }

    }
}